package com.ttl.bc.report.stockrequest;


import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.ttl.common.util.CommonUtils;

public class RptStockRequestAction extends Action {
	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		DynaActionForm stkReq = (DynaActionForm)form;
		String docNo = stkReq.getString("docNo");

		//System.out.println("stock request: docNo = "+docNo);
								
		HashMap hashMap = new HashMap();
		hashMap.put("docNo", docNo);

		String nameOfReport = "/ireport/rptStockRequest.jasper";
		if(CommonUtils.runReportToPdf(response, getServlet(), hashMap, nameOfReport)==true) {
			System.out.println("run report to pdf: complete");
		}else {
			System.out.println("run Report to pdf: can't run report");
		}
//		Connection connection;
//		ServletOutputStream servletOutputStream = response.getOutputStream();
//		
//		InputStream reportStream = getServlet().getServletConfig()
//							.getServletContext().getResourceAsStream("/ireport/rptStockRequest.jasper");
//
//		
//		response.setContentType("application/pdf");
//		//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//		Class.forName("net.sourceforge.jtds.jdbc.Driver");		
////		connection = DriverManager.getConnection("jdbc:odbc:ttl51","sa","admin123");
//		connection = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.1.2:1433/ttl51;user=sa;password=admin@123");
//
//		
//		JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, hashMap, connection);
//		connection.close();
//		servletOutputStream.flush();
//		servletOutputStream.close();
		
		return mapping.getInputForward();
	}
}
